package sseGameApps.controller.mdkbr.main;

//import java.util.HashMap;
//import java.util.Map;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import sseGameApps.model.mdkbr.MdKbrUser;
import sseGameApps.model.mdkbr.MdUseKanji;
import sseGameApps.service.mdkbr.MdKanjiService;
import sseGameApps.service.mdkbr.MdKbrUserService;

public class IndexController extends Controller {

    private MdKanjiService serviceMdKanji = new MdKanjiService();
    private MdKbrUserService serviceMdKbrUser = new MdKbrUserService();

    @Override
    public Navigation run() throws Exception {

        requestScope("userId", asString("userId"));

        requestScope("eneId", "教官");
        requestScope("enemyName", "教官");
        requestScope("enemyBarPoint", "0");
        requestScope("enemyBarPointBefore", "0");
        requestScope("enemyAttackPoint", "0");
        requestScope("enemyKanji01", "壱");
        requestScope("enemyKanji02", "弐");
        requestScope("enemyKanji03", "参");
        requestScope("enemyTypeSp1", 1);
        requestScope("enemyTypeSp2", 1);
        requestScope("enemyTypeSp3", 1);
        requestScope("enemyTypeSp4", 1);
        requestScope("enemyTypeSp5", 1);
        requestScope("enemyCG", "m_000L.png");

        if (!"".equals(asString("userId"))) {
            MdKbrUser mdKbrUserP =
                serviceMdKbrUser.getMdKbrUser(asString("userId"));

            if (mdKbrUserP != null) {
                requestScope("playerName", mdKbrUserP.getPlayerName());
                requestScope("playerSchool", mdKbrUserP.getPlayerSchool());
                requestScope("playerSex", mdKbrUserP.getPlayerSex());
                requestScope("playerType", mdKbrUserP.getPlayerType());
                requestScope("userExp", mdKbrUserP.getUserExp());
                requestScope("userLevel", mdKbrUserP.getUserLevel());
                requestScope("battleCount", mdKbrUserP.getBattleCount());
                requestScope("winCount", mdKbrUserP.getWinCount());
                requestScope("loseCount", mdKbrUserP.getLoseCount());
                requestScope("playerCG", mdKbrUserP.getPlayerCGType());

                MdUseKanji mdUseKanji =
                        serviceMdKanji
                            .getMdUseKanji(mdKbrUserP.getUserId());

                if (mdUseKanji != null) {
                    requestScope("playerBarPoint", mdUseKanji.getUserBp().toString());
                    requestScope("playerBarPointBefore", mdUseKanji.getUserBp().toString());
                    requestScope("playerAttackPoint", mdUseKanji.getUserAp().toString());
                    if (mdUseKanji.getUsingKanji01() == null){
                        requestScope("playerKanji01", "");
                    } else {
                        requestScope("playerKanji01", mdUseKanji.getUsingKanji01());
                    }
                    if (mdUseKanji.getUsingKanji02() == null){
                        requestScope("playerKanji02", "");
                    } else {
                        requestScope("playerKanji02", mdUseKanji.getUsingKanji02());
                    }
                    if (mdUseKanji.getUsingKanji03() == null){
                        requestScope("playerKanji03", "");
                    } else {
                        requestScope("playerKanji03", mdUseKanji.getUsingKanji03());
                    }
                    requestScope("playerTypeSp1", 1);
                    requestScope("playerTypeSp2", 1);
                    requestScope("playerTypeSp3", 1);
                    requestScope("playerTypeSp4", 1);
                    requestScope("playerTypeSp5", 1);

                    requestScope("holderKanji01", mdUseKanji.getHolderKanji01());
                    requestScope("holderKanji02", mdUseKanji.getHolderKanji02());
                    requestScope("holderKanji03", mdUseKanji.getHolderKanji03());
                    requestScope("holderKanji04", mdUseKanji.getHolderKanji04());
                    requestScope("holderKanji05", mdUseKanji.getHolderKanji05());
                    requestScope("holderKanji06", mdUseKanji.getHolderKanji06());
                    requestScope("holderKanji07", mdUseKanji.getHolderKanji07());
                    requestScope("holderKanji08", mdUseKanji.getHolderKanji08());
                    requestScope("usingKanji01", mdUseKanji.getUsingKanji01());
                    requestScope("usingKanji02", mdUseKanji.getUsingKanji02());
                    requestScope("usingKanji03", mdUseKanji.getUsingKanji03());
                    requestScope("usingKanjiType01", mdUseKanji.getUsingKanjiType01());
                    requestScope("usingKanjiType02", mdUseKanji.getUsingKanjiType02());
                    requestScope("usingKanjiType03", mdUseKanji.getUsingKanjiType03());
                    requestScope("userBP", mdUseKanji.getUserBp());
                    requestScope("userAP", mdUseKanji.getUserAp());

                    requestScope("kanji01Bp", 0);
                    requestScope("kanji02Bp", 0);
                    requestScope("kanji03Bp", 0);
                    requestScope("kanji04Bp", 0);
                    requestScope("kanji05Bp", 0);
                    requestScope("kanji06Bp", 0);
                    requestScope("kanji07Bp", 0);
                    requestScope("kanji08Bp", 0);
                    requestScope("kanji01Ap", 0);
                    requestScope("kanji02Ap", 0);
                    requestScope("kanji03Ap", 0);
                    requestScope("kanji04Ap", 0);
                    requestScope("kanji05Ap", 0);
                    requestScope("kanji06Ap", 0);
                    requestScope("kanji07Ap", 0);
                    requestScope("kanji08Ap", 0);
                    requestScope("kanji01Type", "");
                    requestScope("kanji02Type", "");
                    requestScope("kanji03Type", "");
                    requestScope("kanji04Type", "");
                    requestScope("kanji05Type", "");
                    requestScope("kanji06Type", "");
                    requestScope("kanji07Type", "");
                    requestScope("kanji08Type", "");
                    requestScope("kanji01TypeTxt", "");
                    requestScope("kanji02TypeTxt", "");
                    requestScope("kanji03TypeTxt", "");
                    requestScope("kanji04TypeTxt", "");
                    requestScope("kanji05TypeTxt", "");
                    requestScope("kanji06TypeTxt", "");
                    requestScope("kanji07TypeTxt", "");
                    requestScope("kanji08TypeTxt", "");

                    return forward("index.jsp");
                }
            } else {
                requestScope("playerName", asString("userId"));
                requestScope("playerSchool", "001");
                requestScope("playerSex", "1");
                requestScope("playerType", "KI");
                requestScope("userExp", 0);
                requestScope("userLevel", 1);
                requestScope("battleCount", 0);
                requestScope("winCount", 0);
                requestScope("loseCount", 0);
            }
        } else {
            requestScope("playerSex", "1");
            requestScope("playerType", "KI");
            requestScope("userExp", 0);
            requestScope("userLevel", 1);
            requestScope("battleCount", 0);
            requestScope("winCount", 0);
            requestScope("loseCount", 0);
        }
        requestScope("playerBarPoint", "0");
        requestScope("playerBarPointBefore", "0");
        requestScope("playerAttackPoint", "0");
        requestScope("playerKanji01", "");
        requestScope("playerKanji02", "");
        requestScope("playerKanji03", "");
        requestScope("playerTypeSp1", 1);
        requestScope("playerTypeSp2", 1);
        requestScope("playerTypeSp3", 1);
        requestScope("playerTypeSp4", 1);
        requestScope("playerTypeSp5", 1);
        requestScope("playerCG", "m_001R.png");

        requestScope("holderKanji01", "");
        requestScope("holderKanji02", "");
        requestScope("holderKanji03", "");
        requestScope("holderKanji04", "");
        requestScope("holderKanji05", "");
        requestScope("holderKanji06", "");
        requestScope("holderKanji07", "");
        requestScope("holderKanji08", "");
        requestScope("usingKanji01", "");
        requestScope("usingKanji02", "");
        requestScope("usingKanji03", "");
        requestScope("usingKanjiType01", "");
        requestScope("usingKanjiType02", "");
        requestScope("usingKanjiType03", "");
        requestScope("userBP", 0);
        requestScope("userAP", 0);
        requestScope("kanji01Bp", 0);
        requestScope("kanji02Bp", 0);
        requestScope("kanji03Bp", 0);
        requestScope("kanji04Bp", 0);
        requestScope("kanji05Bp", 0);
        requestScope("kanji06Bp", 0);
        requestScope("kanji07Bp", 0);
        requestScope("kanji08Bp", 0);
        requestScope("kanji01Ap", 0);
        requestScope("kanji02Ap", 0);
        requestScope("kanji03Ap", 0);
        requestScope("kanji04Ap", 0);
        requestScope("kanji05Ap", 0);
        requestScope("kanji06Ap", 0);
        requestScope("kanji07Ap", 0);
        requestScope("kanji08Ap", 0);
        requestScope("kanji01Type", "");
        requestScope("kanji02Type", "");
        requestScope("kanji03Type", "");
        requestScope("kanji04Type", "");
        requestScope("kanji05Type", "");
        requestScope("kanji06Type", "");
        requestScope("kanji07Type", "");
        requestScope("kanji08Type", "");
        requestScope("kanji01TypeTxt", "");
        requestScope("kanji02TypeTxt", "");
        requestScope("kanji03TypeTxt", "");
        requestScope("kanji04TypeTxt", "");
        requestScope("kanji05TypeTxt", "");
        requestScope("kanji06TypeTxt", "");
        requestScope("kanji07TypeTxt", "");
        requestScope("kanji08TypeTxt", "");

        return forward("index.jsp");
    }
}
